﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace LibFriesland_Campina_CRM
{
    public class BizInvoiceDetail
    {
        #region Thuoc tinh
        public long by_invoice { get; set; }
        public string by_product { get; set; }
        public int quantity { get; set; }
        public decimal price { get; set; }
        public string shopper_nickname { get; set; }
        public string shopper_name { get; set; }
        public string datetime_invoice_str { get; set; }
        public DateTime? datetime_invoice { get { return Thuvien.myConvertStringToLongDate(datetime_invoice_str); } }
        public string sale_comment { get; set; }
        public string session_invoice { get; set; }
        public string by_product_catalouge { get; set; }
        public string by_product_catalouge_name { get; set; }
        public string by_product_name { get; set; }
        #endregion

        #region Ham thiet lap
        public BizInvoiceDetail() { }
        public BizInvoiceDetail(long pBy_invoice, string pBy_product, int pQuantity)
        {
            by_invoice = pBy_invoice;
            by_product = pBy_product;
            quantity = pQuantity;
        }
        public BizInvoiceDetail(long pBy_invoice, string pBy_product, int pQuantity, decimal pPrice)
        {
            by_invoice = pBy_invoice;
            by_product = pBy_product;
            quantity = pQuantity;
            price = pPrice;

        }
        public BizInvoiceDetail(string pBy_product_name, string pBy_product, int pQuantiy,  string pBy_product_catalouge, string pBy_product_catalouge_name, string pDatetime_invoice_str)
        {
            by_product = pBy_product;
            quantity = pQuantiy;
            by_product_catalouge = pBy_product_catalouge;
            by_product_catalouge_name = pBy_product_catalouge_name;
            datetime_invoice_str = pDatetime_invoice_str;
            by_product_name = pBy_product_name;
        }
        #endregion

        #region Phuong thuc
        //Them mot InvoiceDetail cho mot Invoice
        public int addInvoiceDetail()
        {
            return DalInvoiceDetail.addInvoiceDetail(this);
        }

        //Xoa moi InvoiceDetail cho mot Invoice
        public static int deleteInvoiceDetail(long pBy_invoice, string pBy_product)
        {
            return DalInvoiceDetail.deleteInvoiceDetail(pBy_invoice, pBy_product);
        }

        //Cap nhat thong tin cho mot InvoiceDetail
        public int updateInvoiceDetail()
        {
            return DalInvoiceDetail.updateInvoiceDetail(this);
        }

        //Thay doi so luong san pham cua mot InvoiceDetail
        public int changeInvoiceDetailQuantity()
        {
            return DalInvoiceDetail.changeInvoiceDetailQuantity(this);
        }

        #endregion

        #region Dung cho Webservice
        //Lay thong tin chi tiet ban hang theo ngay
        public static List<BizInvoiceDetail> getInvoiceDetailbyDateNAShop(DateTime pDatetime, string pBy_na, string pBy_shop)
        {
            return DalInvoiceDetail.getInvoiceDetailbyDateNAShop(pDatetime, pBy_na, pBy_shop);
        }

        //Thong ke tong so luong ban duoc tung san pham cua NA theo ngay tai Shop
        public static List<BizProductSale> getSalebyDateNAShop(DateTime pDatetime, string pBy_na, string pBy_shop)
        {
            return DalInvoiceDetail.getSalebyDateNAShop(pDatetime, pBy_na, pBy_shop);
        }
        #endregion

        #region Dung cho Report
        //Thong ke doanh so ban hang cua NA
        public static Dataset.DatasetNaSale getSalebyDateNa(DateTime pFromDate, DateTime pToDate, string pBy_na)
        {
            return DalInvoiceDetail.getSalebyDateNa(pFromDate, pToDate, pBy_na);
        }

        //Thong ke doanh so ban hang cua Sup
        public static Dataset.DatasetSupSale getSalebyDateSup(DateTime pFromDate, DateTime pToDate, string pBy_sup)
        {
            return DalInvoiceDetail.getSalebyDateSup(pFromDate, pToDate, pBy_sup);
        }

        //Thong ke doanh so ban hang cua Shop
        public static Dataset.DatasetShopSale getSalebyDateShop(DateTime pFromDate, DateTime pToDate)
        {
            return DalInvoiceDetail.getSalebyDateShop(pFromDate, pToDate);
        }
        #endregion
    }

    public class BizProductSale
    {
        public BizProductSale() { }
        public BizProductSale(string pBy_product, int pQuantity)
        {
            by_product = pBy_product;
            quantity = pQuantity;
        }
        public string by_product { get; set; }
        public int quantity { get; set; }
    }
}
